﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace calculator
{
    class TruthTableHTMLWriteOut
    {
        public void printTable(TruthTable t)
        {
            using (StreamWriter writer = new StreamWriter("expression.html"))
            {
                writer.WriteLine("<head>");
                writer.WriteLine("<title>" + t.getName() + "</title>");
                writer.WriteLine("<style type=\"text/css\">");
                writer.WriteLine("<!--");
                writer.WriteLine("@import url(\"style.css\");");
                writer.WriteLine("-->");
                writer.WriteLine("</style>");
                writer.WriteLine("</head>");
                writer.WriteLine("<body>");
                writer.WriteLine("<table id = \"ver-zebra\">");
                writer.WriteLine("<colgroup>");
                for (int i = 0; i < t.getLength(); i++)
                {
                    if ((i % 2) == 0)
                        writer.WriteLine("<col class =\"vzebra-even\" />");
                    else
                        writer.WriteLine("<col class =\"vzebra-odd\" />");
                }
                writer.WriteLine("</colgroup>");
                writer.WriteLine("<thead>");
                writer.WriteLine("<tr>");
                for (int i = 0; i < t.getLength(); i++)
                {
                    if ((i % 2) == 0)
                        writer.WriteLine("<th scope=\"col\" id=\"zebra-even\">" + t.getRow(i).getName() + "</th>");
                    else
                        writer.WriteLine("<th scope=\"col\" id=\"zebra-odd\">" + t.getRow(i).getName() + "</th>");
                }
                writer.WriteLine("</tr>");
                writer.WriteLine("</thead>");
                writer.WriteLine("<tbody>");
                writer.WriteLine("<tr>");

                for (int i = 0; i < t.getRow(0).getRow().Length; i++)
                {
                    writer.WriteLine("<tr>");
                    for (int j = 0; j < t.getLength(); j++)
                    {
                        writer.WriteLine("<td>" + t.getRow(j).getValue(i).ToString() + "</td>");
                    }
                    writer.WriteLine("</tr>");
                }
                writer.WriteLine("</tbody>");
                writer.WriteLine("</table>");

                writer.Close();
            }
        }
    }
}